package com.yssw.image.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yssw.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yssw.common.annotation.Log;
import com.yssw.common.core.controller.BaseController;
import com.yssw.common.core.domain.AjaxResult;
import com.yssw.common.enums.BusinessType;
import com.yssw.image.domain.ImageTable;
import com.yssw.image.service.IImageTableService;
import com.yssw.common.utils.poi.ExcelUtil;
import com.yssw.common.core.page.TableDataInfo;

/**
 * 图片资源Controller
 * 
 * @author yssw
 * @date 2023-05-09
 */
@Anonymous
@RestController
@RequestMapping("/image/image")
public class ImageTableController extends BaseController
{
    @Autowired
    private IImageTableService imageTableService;

    /**
     * 查询图片资源列表
     */
//    @PreAuthorize("@ss.hasPermi('image:image:list')")
    @GetMapping("/list")
    public TableDataInfo list(ImageTable imageTable)
    {
        startPage();
        List<ImageTable> list = imageTableService.selectImageTableList(imageTable);
        return getDataTable(list);
    }
    /**
     * 导出图片资源列表
     */
    @PreAuthorize("@ss.hasPermi('image:image:export')")
    @Log(title = "图片资源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ImageTable imageTable)
    {
        List<ImageTable> list = imageTableService.selectImageTableList(imageTable);
        ExcelUtil<ImageTable> util = new ExcelUtil<ImageTable>(ImageTable.class);
        util.exportExcel(response, list, "图片资源数据");
    }

    /**
     * 获取图片资源详细信息
     */
    @PreAuthorize("@ss.hasPermi('image:image:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(imageTableService.selectImageTableById(id));
    }

    /**
     * 新增图片资源
     */
    @PreAuthorize("@ss.hasPermi('image:image:add')")
    @Log(title = "图片资源", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ImageTable imageTable)
    {
        return toAjax(imageTableService.insertImageTable(imageTable));
    }

    /**
     * 修改图片资源
     */
    @PreAuthorize("@ss.hasPermi('image:image:edit')")
    @Log(title = "图片资源", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ImageTable imageTable)
    {
        return toAjax(imageTableService.updateImageTable(imageTable));
    }

    /**
     * 删除图片资源
     */
    @PreAuthorize("@ss.hasPermi('image:image:remove')")
    @Log(title = "图片资源", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(imageTableService.deleteImageTableByIds(ids));
    }
}
